home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / aliascfg.cmd < prev    next >
OS/2 REXX Batch file  |  1997-03-21  |  16KB  |  462 lines

  1. /*  */
  2. aliascfg:
  3. CHECKIT=0   /* Change this to 0 if you want to enable REMOTE configuration */
  4.  
  5. /* background color */
  6. USECOLOR='2dd52f'
  7.  
  8.  
  9. /* ---------------- DO NOT MODIFY BELOW THIS LINE  ------------------ */
  10.  
  11. parse arg ddir,tempfile,sel,list,verb,uri,user,basedir,workdir,privset,enmadd,transaction,verbose
  12.  
  13. if verb="" then do
  14.    say " This SRE-Filter add-on is NOT meant to be run from the command line."
  15.    say " It can be invoked by using CONFIGUR.HTM "
  16.    exit
  17. end  /* Do */
  18.  
  19.  
  20. list=translate(list, ' ', '+'||'090a0d'x)  /* Whitespace, etc. */
  21.  
  22. who2=extract('CLIENTADDR')
  23. saddr2=extract('SERVERADDR')
  24.  
  25. select
  26.    when checkit=1 then do
  27.  
  28. /* only if user = serveraddress !!! */
  29.      if who2<>saddr2 then do
  30.  
  31.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  32.         call lineout tempfile, "<html><head><title>SREFILTER ERROR </title>"
  33.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  34.  
  35.         call lineout tempfile,' <strong> Action not allowed remotely.</strong> <pre>'
  36.         call lineout tempfile,' </body> </html> '
  37.         call lineout tempfile
  38.         'FILE ERASE TYPE text/html NAME' tempfile
  39.         return 'ALIASCFG: action not allowed remotely. '
  40.      end
  41.    end
  42.    otherwise do
  43.       if wordpos('SUPERUSER',privset)=0 then do
  44.         'RESPONSE HTTP/1.0 401 Unauthorized '     /* Set HTTP response line */
  45.         'header add WWW-Authenticate: Basic Realm=<CONFIGURE>'  /* challenge */
  46.  
  47.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  48.         call lineout tempfile, "<html><head><title>Not authorized </title>"
  49.         call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  50.  
  51.  
  52.         call lineout tempfile,' <strong> You do not have configuration rights.</strong> <pre>'
  53.         if who2=saddr2 then 
  54.                 call lineout tempfile,'<br> <Em> You may want to edit USERCFG.CMD </em> '
  55.         call lineout tempfile,' </body> </html> '
  56.         call lineout tempfile
  57.          iia=dosdir(tempfile,'s')
  58.         'FILE ERASE TYPE text/html NAME' tempfile
  59.         return '401 'iia' ALIASCFG: not permitted to configure. '
  60.       end
  61.    end
  62. end
  63.  
  64. list=strip(list)
  65. select 
  66.    when upper(list)='TODO=SHOW' | upper(list)='TODO=SHOW_HEADER' then
  67.         signal doshow
  68.    when upper(list)='TODO=SET' then
  69.         signal doset
  70.    otherwise
  71.         signal dochange
  72. end  /* select */
  73.  
  74. /* jump here to show values */
  75. doshow:
  76.  
  77. aliasfile=value(enmadd||'ALIAS_FILE',,'os2environment')
  78.    call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  79.    call lineout tempfile, "<html><head><title>SRE-Filter redirection aliases </title>"
  80.    call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  81.  
  82.  
  83. aa=go_fileread(aliasfile)  /* expose lins */
  84.  
  85. /*aa=fileread(aliasfile,'lins',,'E') */
  86.  
  87. call lineout tempfile, "<h1> SRE-Filter: <A NAME="top"> Redirection aliases </A>   </h1> <p>"
  88. if upper(list)="TODO=SHOW"  then
  89.    call lineout tempfile, "<h2> List of "header" comments </h2> <pre> <blockquote>"
  90. else
  91.    call lineout tempfile, "<h2> Description of redirection aliaases </h2> <pre> <blockquote>"
  92.  
  93.  
  94. /* show "header comments" */
  95. iat=0
  96. do until iat >= lins.0
  97.    iat=iat+1
  98.    if  abbrev(strip(lins.iat),';')  then do
  99.         foo=strip(lins.iat) ;foo=strip(foo,'l',';')
  100.          call lineout tempfile, foo 
  101.    end  /* Do */
  102.    else do
  103.         leave
  104.    end
  105. end /* do -- iat is the first non header comment line  */
  106. call lineout tempfile, '</blockquote></pre> '
  107.  
  108. /* view descriptive header only? */
  109. if upper(list)='TODO=SHOW_HEADER' then do
  110.    call lineout tempfile,' <hr> </body></html>'
  111.    call lineout tempfile
  112.    'file erase  type text/html name  ' tempfile
  113.    return ' done '
  114. end  /* Do */
  115.  
  116. /* read in aliases, etc */
  117. nusers=0
  118. call lineout tempfile, '<hr><h2> List of redirection aliases </h2> '
  119. call lineout tempfile,' Notes: <ul> '
  120. call lineout tempfile,' <li> Aliases are stored in: ' aliasfile
  121. call lineout tempfile,' <li> <em>Comments are in italics </em> '
  122. call lineout tempfile,' <li> The <strong>*</strong> character is used as a wildcard (for an arbitrarily long string)'
  123. call lineout tempfile, ' <li> Entries with no <strong>host nickname</strong> apply to all requests</ul> <br>'
  124. call lineout tempfile,' <table border=1> <th> Host Nickname </th>'
  125. call lineout tempfile,' <th> Candidate SEL (convert from)</th>'
  126. call lineout tempfile,'  <th> Target of redirection (convert to) </th> <tr>'
  127.  
  128. do mm=iat to lins.0
  129.   if lins.mm=' ' then iterate
  130.   if  abbrev(strip(lins.mm),';') then do  
  131.        call lineout tempfile,'<td colspan=3>  <code>     </code> <em>' strip(strip(lins.mm),'l',';') '</em></td> <tr> '
  132.   end
  133.   else do
  134.       if pos('// ',lins.mm)>0 then do
  135.            parse var lins.mm hostname '//' candurl targurl
  136.       end
  137.       else do
  138.            hostname=' .. '
  139.            parse var lins.mm candurl targurl
  140.       end  /* Do */
  141.       if length(targurl) > 55 then do
  142.           iiat2=0 ; moocow='' ; ijoe=length(targurl) 
  143.           do while iiat2 <= length(targurl)
  144.               iiat=iiat2+1
  145.               eek=substr(targurl,iiat,45)
  146.               moocow=moocow||eek||'<br>'
  147.               iiat2=iiat2+45
  148.           end
  149.           targurl=moocow
  150.       end
  151.       call lineout tempfile,'<td>     <STRONG> 'hostname '</STRONG> </td>'
  152.       call lineout tempfile,'<td>   <STRONG> ' candurl '</STRONG> </td>'
  153.       call lineout tempfile,'<td>    <STRONG> 'targurl '</STRONG> </td> <tr>'
  154.  
  155.   end /* do */
  156.  
  157. end
  158. call lineout tempfile,' </table>'
  159.  
  160. call lineout tempfile,' <hr> Thanks for checking </body></html>'
  161. call lineout tempfile
  162.  
  163. foo=sref_expire_response(0.05,dosdir(tempfile,'s'))
  164. 'file erase  type text/html name  ' tempfile
  165. return ' done '
  166.  
  167.  
  168.  
  169. /* --- jump here to modify values -- */
  170. /* jump here if "set values" chosen */
  171. doset:
  172. aliasfile=value(enmadd||'ALIAS_FILE',,'os2environment')
  173.  
  174. aa=go_fileread(aliasfile)
  175. /*aa=fileread(aliasfile,'lins',,'E')*/
  176.  
  177. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  178. call lineout tempfile, "<html><head><title>SRE-Filter: modify redirection aliases </title>"
  179. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  180.  
  181.  
  182. /* ignore header stuff */
  183. iat=0
  184. do until iat >= lins.0
  185.    iat=iat+1
  186.    if  abbrev(strip(lins.iat),';') | lins.iat=' ' then iterate
  187.    leave
  188. end /* do -- iat is the first non header comment line  */
  189. call lineout tempfile, "<h1> SRE-Filter: modify redirection Aliases  </h1> <p>"
  190. call lineout tempfile,' <blockquote> You can modify, remove, or add redirection aliases.'
  191. call lineout tempfile,' <br><em> Questions? <A HREF="#notes">The notes might help.</A> </em> </blockquote> '
  192. call lineout tempfile,' <h2> Modify or remove current Aliases </h2>'
  193. call lineout tempfile,'<FORM ACTION="/aliascfg" METHOD="POST">'
  194. call lineout tempfile,' <table border=1> <th> Host Nickname <br> (see below  for a <br>listing of <A HREF="#hosts">current hosts</A>) </th>'
  195. call lineout tempfile,' <th> Candidate SEL   (set to blank to  <br> delete the entry)</th>'
  196. call lineout tempfile,'  <th> Target SEL   </th> <tr>'
  197.  
  198. nhidden=0 ; mm=0
  199. do mm0=iat to lins.0
  200.     alin=translate(lins.mm0,' ','1a000d0a'x)
  201.     mm=mm+1
  202.     if  abbrev(strip(alin),';')=1 | alin=' ' then do
  203.         nhidden=nhidden+1
  204.         hiddens.nhidden='<INPUT TYPE="HIDDEN" name="COMMENT.'||mm||'"  value="'||alin||'" >'
  205.         iterate
  206.     end
  207.  
  208. /* non comment */
  209.     if pos('// ',alin)>0 then
  210.              parse var alin hostname '//' candurl targurl
  211.         else do
  212.              hostname='  '
  213.              parse var alin candurl targurl
  214.      end  /* Do */
  215.      call lineout tempfile,'<td> <EM>Host nickname:</EM> <br> <INPUT TYPE="text" NAME="hostname.'||mm||'"'
  216.      call lineout tempfile,'value="'hostname'" SIZE=8 MAXLENGTH=15> </td> '
  217.      call lineout tempfile,'<td> <EM>Candidate SEL:</EM> <br> <INPUT TYPE="text" NAME="candurl.'||mm||'"'
  218.      call lineout tempfile,'value="'candurl'" SIZE=28 MAXLENGTH=295> </td> '
  219.      call lineout tempfile,'<td> <EM>Target SEL:</EM> <br> <INPUT TYPE="text" NAME="targurl.'||mm||'"'
  220.      call lineout tempfile,'value="'targurl'" SIZE=28 MAXLENGTH=295> </td> '
  221.      if mm0<lins.0 then do
  222.            call lineout tempfile,'<tr>' ; call lineout tempfile,' '
  223.      end
  224. end
  225. call lineout tempfilem,' '
  226.  
  227. /* --- allow user to enter a few new names */
  228. call lineout tempfile,' </table>  <p> <h2> Add new redirection aliases </h2> <table border=1>'
  229. mm0=mm
  230. do mm=mm0+1 to mm0+3
  231.      call lineout tempfile,'<td> <EM>Host nickname:</EM> <br> <INPUT TYPE="text" NAME="hostname.'||mm||'"'
  232.      call lineout tempfile,'value=" " SIZE=8 MAXLENGTH=15> </td> '
  233.      call lineout tempfile,'<td> <EM>Candidate SEL:</EM> <br> <INPUT TYPE="text" NAME="candurl.'||mm||'"'
  234.      call lineout tempfile,'value=" " SIZE=28 MAXLENGTH=295> </td> '
  235.      call lineout tempfile,'<td> <EM>Target SEL:</EM> <br> <INPUT TYPE="text" NAME="targurl.'||mm||'"'
  236.      call lineout tempfile,'value=" " SIZE=28 MAXLENGTH=295> </td> '
  237.      if mm<mm0+3 then call lineout tempfile,' <tr> '
  238. end
  239.  
  240. call lineout tempfile,'</table> <p>'
  241.  
  242.  
  243. /* ----- add comments information */
  244.  
  245. do jj=1 to nhidden
  246.    call lineout tempfile,hiddens.jj
  247. end /* do */
  248. call lineout tempfile,' <input type="hidden" name="entries" value="'||mm||'">'
  249. call lineout tempfile,' <input type="submit"> <input type="reset"> </form> '
  250.  
  251.  
  252. call lineout tempfile,' <hr> <h3><A NAME="notes"> Notes</A> </h3> <ul> <li> Aliases are stored in: 'aliasfile
  253. call lineout tempfile,' <li> If a <em>request selector</em> matches a <em>candidate SEL</em>, '
  254. call lineout tempfile,' <br> the associated <em>target SEL </em> is for the (internal or external) redirection'
  255. call lineout tempfile,' <li> To add more then 3 new aliases, just rerun this several times <br> or edit ' aliasfile
  256. call lineout tempfile,' <li> Do you want to view a  more complete description of '
  257. call lineout tempfile,' <a href="/aliascfg?TODO=SHOW_HEADER"> aliases </a>?'
  258. call lineout tempfile,' <li> <em>Comments are NOT displayed </em>  <li> Case is ignored '
  259. call lineout tempfile,' <li> Use a <strong>* </strong> in the <em>candidate SEL</em> as a wildcard character '
  260. call lineout tempfile,' <li> When a * appears in the <em>candidate SEL</em>.. '
  261. call lineout tempfile,' <br> you can use a <strong>* </strong> in the <em>target SEL</em> as a placeholder for the wildcard match '
  262. call lineout tempfile,' <li> A <em>Target SEL</em> being used for external redirection should start with <strong>http:// </strong>'
  263. call lineout tempfile, ' <li> Entries with no <strong>host nickname</strong> will apply to all requests</ul> <br>'
  264.  
  265. call lineout tempfile,' <h3> A list of the current <A name="hosts">hosts</A> </h3>  <blockquote> '
  266.  
  267. ii=value(enmadd||'HOSTS.0',,'os2environment')
  268. if ii>0 then do
  269. call lineout tempfile,' <table> <th> IP address </th> <th> Host Nickname </th> <th> Data Directory </th> <tr> '
  270. do ll=1 to ii
  271.    wow=value(enmadd||'HOSTS.'||ll,,'os2environment')
  272.    parse var wow ip ',' hn ',' hdir
  273.    call lineout tempfile,' <td> ' ip  '</td> <td> ' hn ' </td> <td> ' hdir '</td> <tr> '
  274. end /* do */
  275. call lineout tempfile,' </table> </blockquote>'
  276. end
  277. else do
  278.   call lineout tempfile,' No HOSTS have been defined   </blockquote>'
  279. end
  280.  
  281. call lineout tempfile,' <p> <A HREF="#top">Return to the top of this form.</A>'
  282.  
  283. call lineout tempfile,'</body></html>'
  284. call lineout tempfile
  285.  
  286. foo=sref_expire_response(0.05,dosdir(tempfile,'s'))
  287. 'file erase  type text/html name  ' tempfile
  288. return ' done '
  289.  
  290.  
  291.  
  292. /* ********************** jump here to recrod changes */
  293. dochange:
  294.  
  295. parse upper var list foo 'ENTRIES=' nentries '&' .
  296. do ii1=1 to nentries
  297.    fillme.ii1.0=0
  298. end /* do */
  299.  
  300. do until list=""
  301.    parse var list aa '&' list
  302.    parse  var aa avar '.' aind '=' aval
  303.    avar=upper(avar)
  304.    aval=packur(aval)
  305.    if abbrev(upper(avar),'ENTRIES=')=1 then iterate
  306.    wow=fillme.aind.0+1
  307.    fillme.aind.0=wow
  308.    fillme.aind.wow.var=avar ; fillme.aind.wow.val=aval
  309.    select
  310.       when avar="COMMENT" then do
  311.           fillme.aind.type='COMMENT'
  312.           parse  var aa foo '=' aval
  313.           fillme.aind.wow.val=packur(aval)
  314.       end
  315.       when avar="CANDURL" then fillme.aind.type='URL'
  316.       otherwise nop
  317.    end
  318. end /* do */
  319.  
  320. aliasfile=value(enmadd||'alias_FILE',,'os2environment')
  321. aa=go_fileread(aliasfile)
  322. /*aa=fileread(aliasfile,'lins',,'E')*/
  323.  
  324. /* pull "header comments" */
  325. iat=0
  326. do until iat >= lins.0
  327.    iat=iat+1
  328.    if  abbrev(strip(lins.iat),';')  then do
  329.        newlines.iat=lins.iat
  330.    end  /* Do */
  331.    else do
  332.         leave
  333.    end
  334. end /* do -- iat is the first non header comment line  */
  335. iat=iat-1
  336.  
  337. do uu=1 to nentries
  338.    select
  339.       when fillme.uu.type='COMMENT' then do
  340.           iat=iat+1
  341.           newlines.iat=fillme.uu.1.val
  342.       end
  343.       when fillme.uu.type='URL' then do
  344.           candurl=' ' ; targurl=' ' ; hostname=' ' 
  345.           do uu2=1 to fillme.uu.0
  346.              chk1=fillme.uu.uu2.var
  347.              vvv=fillme.uu.uu2.val
  348.              select
  349.                 when chk1='CANDURL' then candurl=vvv
  350.                 when chk1='TARGURL' then targurl=vvv
  351.                 when chk1='HOSTNAME' then hostname=vvv
  352.                 otherwise nop
  353.              end
  354.           end
  355.           if candurl<>' ' then do
  356.               iat=iat+1
  357.               newlines.iat=''
  358.               if hostname<>' ' then
  359.                   newlines.iat=hostname||'// '
  360.               newlines.iat=newlines.iat||candurl' ' targurl
  361.           end
  362.       end
  363.       otherwise do
  364.             nop
  365.       end  /* Do */
  366.  
  367.   end                   /* select over type */
  368. end                     /* do over entries */
  369.  
  370. /* save to aliasfile.. but rename access_file first */
  371. foo=lastpos('.',aliasfile)
  372. if FOO=0 then
  373.    acf1=aliasfile||'.'
  374. else
  375.    acf1=left(aliasfile,foo)
  376. do hi=1 to 999
  377.    try1=acf1||hi
  378.    if stream(acf1||hi,'c','query exists')='' then leave
  379. end /* do */
  380. foo=dosrename(aliasfile,try1)
  381.  
  382.  
  383. newlines.0=iat
  384. foo=filewrite(aliasfile,newlines,'R')
  385.  
  386.  
  387. call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 3.0//EN">'
  388. call lineout tempfile, "<html><head><titLE> SRE-Filter: Changed the aliases</title>"
  389. call lineout tempfile, '</head><body  bgcolor="#'||usecolor||'">'
  390.  
  391. call lineout tempfile,' <h2>The aliases have been changed </h2>'
  392. call lineout tempfile,' The list of aliases has been saved to: ' aliasfile
  393. call lineout tempfile,' <p> The old version of 'aliasfile' has been moved to ' try1
  394. call lineout tempfile,' </body> </html> '
  395. call lineout tempfile
  396.  
  397. foo=value('SREF_REDO',1,'os2environment')
  398.  
  399. foo=sref_expire_response(0.05,dosdir(tempfile,'s'))
  400. 'FILE ERASE TYPE text/html NAME' tempfile
  401. return 'done change '
  402.  
  403.  
  404.  
  405.  
  406. /* read in aliasfile, concatenate  extension lines */
  407. go_fileread:procedure expose lins.
  408. parse arg aliasfile
  409. aa=fileread(aliasfile,'lins0',,'E')
  410. FOO=DO_EXTENDS(0)
  411.  
  412.  
  413. /* OLDER "END WITH , " METHOD RETAINED FOR COMPATABILITIES */
  414. ill=0
  415. exton=0
  416. do il=1 to lins0.0
  417.   t1=strip(lins0.il)
  418.   if exton=1 then do
  419.        t1=t1storage||t1
  420.   end
  421.   exton=0 
  422.  
  423.   if abbrev(t1,';')=0 then do
  424.      if right(t1,2)=' ,' & il < lins0.0 then do
  425.         exton=1
  426.         t1=left(t1,length(t1)-2)
  427.         t1storage=strip(t1)
  428.         iterate
  429.      end
  430.   end
  431.  
  432.   ill=ill+1
  433.   lins.ill=t1
  434. end /* do */
  435.  
  436. lins.0=ill
  437. return ill
  438.  
  439.  
  440. /************/
  441. /* Redo ulist, by treating lines starting with , as continuation lines */
  442. do_extends:procedure expose lins0.
  443.  
  444. if lins0.0=0 then return
  445. isnew=1
  446. tmps.1=lins0.1
  447. do mm=2 to lins0.0
  448.    ali=strip(lins0.mm)
  449.    if abbrev(ali,',')=0 then do
  450.         isnew=isnew+1
  451.         tmps.isnew=lins0.mm
  452.     end
  453.     else do
  454.         tmps.isnew=tmps.isnew||substr(ali,2)
  455.     end
  456. end
  457. do mm=1 to isnew
  458.     lins0.mm=tmps.mm
  459. end
  460. lins0.0=isnew
  461. return 0
  462.